  (function(){
    var $wrap=$("#wrap"),
        $pages=$("#product_list").find(".product_box"),
        $controlBox=$("#control_box"),
        $productBtns=$("#product_btns"),
        $controls=$controlBox.find("a"),
        $icLine=$("#ic_line"),
        $listTops=$("#list_top").find("li"),
        $hNav=$("#h_nav"),
        $hNavli=$hNav.find("li"),
        $hSubnav=$("#h_subnav"),
        $hSubDD=$hSubnav.find("dd"),
        $hBdot=$("#h_bdot"),
        $hSdot=$("#h_sdot"),
        $footer=$("#footer"),
        $bgs=$pages.find(".bg_box img"),
        $mainBoxs=$pages.find(".main_box"),
        $moreNav=$("#more_nav"),
        $rptBg=$("#rpt_bg"),
        $xnetDownload=$("#xnet_download"),
        $xavDownload=$("#xav_download");
    var data={
        pLength:$pages.length,
        curP:-1,
        isCan:true,
        isOnbtn:false,
        fColor:[2,2,1,1,1],
        dur: 5000,
        cNum:0
    };
    var aDD=$controls.eq(0).width()+parseInt($controls.eq(0).css("margin-right").slice(0,-2))*2;
    var cId;
    var isCss3=function(){
      var style=document.createElement("div").style;
        for(var k in style){
          if(k.toLowerCase().indexOf("animation")>=0){
            return true;
          }
         }
         return false;
    }();
    var isIE6=navigator.userAgent.indexOf("MSIE 6.0") > 0;

    //页面自缩放
    var resize=function(){
      var w=$(window).width(),
          h=$(window).height();
      $wrap.height(h);
      $moreNav.height(h);
      if(w/h<1920/1080){
        $bgs.height(h).css({width:"auto",margin:-.5*h+"px 0 0 "+-.5*1920/1080*h+"px"});
      }else{
        $bgs.width(w).css({height:"auto",margin:-.5*w*1080/1920+"px 0 0 "+-.5*w+"px"});
      }
      var imgH=$bgs.height();
      $mainBoxs.height(imgH).css("margin-top",-.5*imgH+"px");
      var cls;
      if(isCss3){
        document.getElementById("wrap").className="wrap big_view css3";
      }else{
        switch(true){
          case w>=1600:{cls="big_view";break;}
          case w<1600&&w>=1440:{cls="mid_view";break;}
          case w<1440:{cls="small_view";break;}
        }
        var ws=$wrap[0].className;
        if(isIE6&&(ws.indexOf("big")!=-1||ws.indexOf("mid")!=-1||ws.indexOf("small")!=-1)&&ws.indexOf(cls)==-1)
          location.reload();
        wrap.className="wrap "+cls;
      }  
      aDD=$controls.eq(0).width()+parseInt($controls.eq(0).css("margin-right").slice(0,-2))*2;   
    };
    $(window).resize(resize);
    resize();
    
    //轮播
    var pageChange=function(idx){
      if(data.isOnbtn)
        return;
      if(idx>=-1&&idx<data.pLength&&idx!=data.curP&&data.isCan){ 
        $productBtns.removeClass("down");
        $xavDownload.removeClass("show");
        $xnetDownload.removeClass("show");
        data.isCan=false; 
        data.cNum++; 
        clearInterval(cId); 
        idx=idx==-1?data.pLength-1:idx;     
        $controls.removeClass("cur").eq(idx).addClass("cur");
        $pages.eq(data.curP).css({zIndex:0});
        $icLine.css({left:aDD*idx});
        // $footer.attr("class","footer f_color"+data.fColor[idx]);
        $pages.eq(idx).addClass("show").css({opacity:0,zIndex:1}).animate({opacity:1},400,function(){
          $pages.eq(data.curP).removeClass("show");
          $(this).addClass("show");
          data.isCan=true;
          data.curP=idx; 
          data.cNum--; 
          if(data.cNum==0){
            cId=setInterval(function(){
              pageChange((data.curP+1)%data.pLength);
            },data.dur);   
          }  
        });
      }
    }
    pageChange(0)
    $controls.on("mouseenter",function(){
      data.isCan=true;
      pageChange($controls.index(this));
      $icLine.css({left:aDD*$controls.index(this)});
      data.isOnbtn=true;
    }).on("mouseleave",function(){
      data.isOnbtn=false;
    }).on("click",function(){
      if($(this).hasClass("btn_xnet9")){
        $xnetDownload.toggleClass("show");
        $productBtns.toggleClass("down");
        bottomHide();
      }
      if($(this).hasClass("btn_xav")){
        $xavDownload.toggleClass("show"); 
        $productBtns.toggleClass("down");
        bottomHide();
      }
    })

    //底部下载区出现时不轮播
    $xnetDownload.on("mouseenter",function(){
      data.isOnbtn=true;
    }).on("mouseleave",function(){
      data.isOnbtn=false;
    });
    $xavDownload.on("mouseenter",function(){
      data.isOnbtn=true;
    }).on("mouseleave",function(){
      data.isOnbtn=false;
    });

    //底部操作
    var isBottom=false;
    var bAni;
    var bottomHide=function(){
      if(isBottom){
        isBottom=false;
        if(bAni)
          clearTimeout(bAni),bAni=null;
        $footer.removeClass("show");
        $productBtns.removeClass("show");
        $rptBg.removeClass("show");
      }    
    }
    var bottomShow=function(){
      if($productBtns.hasClass("down"))
        return;
      if(!isBottom){
        isBottom=true;
        $footer.addClass("show");
        $productBtns.addClass("show");
        $rptBg.addClass("show");
        if(bAni)
          clearTimeout(bAni);
        bAni=setTimeout(bottomHide,2000);
      }
    }
    $footer.on("mouseenter",function(){
      if(bAni)
        clearTimeout(bAni),bAni=null;
    });
    $footer.on("mouseleave",function(){
      if(bAni)
        clearTimeout(bAni);
      bAni=setTimeout(bottomHide,2000);
    });
    $(document).on("mousewheel DOMMouseScroll",function(event){
      var sd=event.originalEvent.wheelDelta||event.originalEvent.detail*-1;
      if(sd>0){
        bottomHide();
      }
      else{
        bottomShow();                         
      }
    });


    //导航事件
    $("#nav_more").on("mouseenter",function(){
      $moreNav.addClass("show");
    });
    $moreNav.on("mouseleave",function(){
      $moreNav.removeClass("show");
      $hBdot.css({left:-9999,top:106});
    })
    $hNavli.on("mouseenter",function(){
      $hBdot.css({left:18,top:106+$hNavli.index(this)*69});
    });
    $hNav.on("mouseleave",function(){
      $hBdot.css({left:-9999});
    });
    $hSubnav.find("dt").on("mouseenter",function(){
      $hBdot.css({left:18});
      $hSdot.css({left:-9999});
    });
    $hSubDD.on("mouseenter",function(){
      $hSdot.css({left:18,top:53+$hSubDD.index(this)*44});
      $hBdot.css({left:-9999});
    });
    $hSubnav.on("mouseleave",function(){
      $hSdot.css({left:-9999});
    });    
  })();
/*
$(function() {
    var Fireworks = function() {
        var self = this;
        var rand = function(rMi, rMa) {
            return ~~((Math.random() * (rMa - rMi + 1)) + rMi);
        }
        var hitTest = function(x1, y1, w1, h1, x2, y2, w2, h2) {
            return !(x1 + w1 < x2 || x2 + w2 < x1 || y1 + h1 < y2 || y2 + h2 < y1);
        };
        window.requestAnimFrame = function() {
            return window.requestAnimationFrame || window.webkitRequestAnimationFrame || window.mozRequestAnimationFrame || window.oRequestAnimationFrame || window.msRequestAnimationFrame || function(a) {
                window.setTimeout(a, 1E3 / 60)
            }
        }();

        self.init = function() {
            self.canvas = document.getElementById('fireworks');
            self.canvas.width = self.cw = $(window).innerWidth();
            self.canvas.height = self.ch = $(window).innerHeight();
            self.particles = [];
            self.partCount = 150;
            self.fireworks = [];
            self.mx = self.cw / 2;
            self.my = self.ch / 2;
            self.currentHue = 30;
            self.partSpeed = 5;
            self.partSpeedVariance = 10;
            self.partWind = 50;
            self.partFriction = 5;
            self.partGravity = 0;
            self.hueMin = 30;
            self.hueMax = 30;
            self.fworkSpeed = 4;
            self.fworkAccel = 10;
            self.hueVariance = 0;
            self.flickerDensity = 25;
            self.showShockwave = true;
            self.showTarget = false;
            self.clearAlpha = 25;
            self.ctx = self.canvas.getContext('2d');
            self.ctx.lineCap = 'round';
            self.ctx.lineJoin = 'round';
            self.lineWidth = 1;
            self.bindEvents();
            self.canvasLoop();

            self.canvas.onselectstart = function() {
                return false;
            };
        };

        self.createParticles = function(x, y, hue) {
            var countdown = self.partCount;
            while (countdown--) {
                var newParticle = {
                    x: x,
                    y: y,
                    coordLast: [{
                        x: x,
                        y: y
                    }, {
                        x: x,
                        y: y
                    }, {
                        x: x,
                        y: y
                    }],
                    angle: rand(0, 360),
                    speed: rand(((self.partSpeed - self.partSpeedVariance) <= 0) ? 1 : self.partSpeed - self.partSpeedVariance, (self.partSpeed + self.partSpeedVariance)),
                    friction: 1 - self.partFriction / 100,
                    gravity: self.partGravity / 2,
                    hue: hue,
                    brightness: rand(50, 80), //调整色彩变化
                    alpha: rand(40, 100) / 100,
                    decay: rand(10, 50) / 1000,
                    wind: (rand(0, self.partWind) - (self.partWind / 2)) / 25,
                    lineWidth: self.lineWidth
                };
                self.particles.push(newParticle);
            }
        };


        self.updateParticles = function() {
            var i = self.particles.length;
            while (i--) {
                var p = self.particles[i];
                var radians = p.angle * Math.PI / 180;
                var vx = Math.cos(radians) * p.speed / 20;
                var vy = Math.sin(radians) * p.speed / 20;
                p.speed *= p.friction;

                p.coordLast[2].x = p.coordLast[1].x;
                p.coordLast[2].y = p.coordLast[1].y;
                p.coordLast[1].x = p.coordLast[0].x;
                p.coordLast[1].y = p.coordLast[0].y;
                p.coordLast[0].x = p.x;
                p.coordLast[0].y = p.y;

                p.x += vx;
                p.y += vy;
                p.y += p.gravity;

                p.angle += p.wind;
                p.alpha -= p.decay;

                if (!hitTest(0, 0, self.cw, self.ch, p.x - p.radius, p.y - p.radius, p.radius * 2, p.radius * 2) || p.alpha < .05) {
                    self.particles.splice(i, 1);
                }
            };
        };

        self.drawParticles = function() {
            var i = self.particles.length;
            while (i--) {
                var p = self.particles[i];

                var coordRand = (rand(1, 3) - 1);
                self.ctx.beginPath();
                self.ctx.moveTo(Math.round(p.coordLast[coordRand].x), Math.round(p.coordLast[coordRand].y));
                self.ctx.lineTo(Math.round(p.x), Math.round(p.y));
                self.ctx.closePath();
                self.ctx.strokeStyle = 'hsla(' + p.hue + ', 100%, ' + p.brightness + '%, ' + p.alpha + ')';
                self.ctx.stroke();

                if (self.flickerDensity > 0) {
                    var inverseDensity = 50 - self.flickerDensity;
                    if (rand(0, inverseDensity) === inverseDensity) {
                        self.ctx.beginPath();
                        self.ctx.arc(Math.round(p.x), Math.round(p.y), rand(p.lineWidth, p.lineWidth + 3) / 2, 0, Math.PI * 2, false)
                        self.ctx.closePath();
                        var randAlpha = rand(50, 100) / 100;
                        self.ctx.fillStyle = 'hsla(' + p.hue + ', 100%, ' + p.brightness + '%, ' + randAlpha + ')';
                        self.ctx.fill();
                    }
                }
            };
        };


        self.createFireworks = function(startX, startY, targetX, targetY) {
            var newFirework = {
                x: startX,
                y: startY,
                startX: startX,
                startY: startY,
                hitX: false,
                hitY: false,
                coordLast: [{
                    x: startX,
                    y: startY
                }, {
                    x: startX,
                    y: startY
                }, {
                    x: startX,
                    y: startY
                }],
                targetX: targetX,
                targetY: targetY,
                speed: self.fworkSpeed,
                angle: Math.atan2(targetY - startY, targetX - startX),
                shockwaveAngle: Math.atan2(targetY - startY, targetX - startX) + (90 * (Math.PI / 180)),
                acceleration: self.fworkAccel / 100,
                hue: self.currentHue,
                brightness: rand(50, 80),
                alpha: rand(50, 100) / 100,
                lineWidth: self.lineWidth
            };
            self.fireworks.push(newFirework);

        };


        self.updateFireworks = function() {
            var i = self.fireworks.length;

            while (i--) {
                var f = self.fireworks[i];
                self.ctx.lineWidth = f.lineWidth;

                vx = Math.cos(f.angle) * f.speed,
                    vy = Math.sin(f.angle) * f.speed;
                f.speed *= 1 + f.acceleration;
                f.coordLast[2].x = f.coordLast[1].x;
                f.coordLast[2].y = f.coordLast[1].y;
                f.coordLast[1].x = f.coordLast[0].x;
                f.coordLast[1].y = f.coordLast[0].y;
                f.coordLast[0].x = f.x;
                f.coordLast[0].y = f.y;

                if (f.startX >= f.targetX) {
                    if (f.x + vx <= f.targetX) {
                        f.x = f.targetX;
                        f.hitX = true;
                    } else {
                        f.x += vx;
                    }
                } else {
                    if (f.x + vx >= f.targetX) {
                        f.x = f.targetX;
                        f.hitX = true;
                    } else {
                        f.x += vx;
                    }
                }

                if (f.startY >= f.targetY) {
                    if (f.y + vy <= f.targetY) {
                        f.y = f.targetY;
                        f.hitY = true;
                    } else {
                        f.y += vy;
                    }
                } else {
                    if (f.y + vy >= f.targetY) {
                        f.y = f.targetY;
                        f.hitY = true;
                    } else {
                        f.y += vy;
                    }
                }

                if (f.hitX && f.hitY) {
                    self.createParticles(f.targetX, f.targetY, f.hue);
                    self.fireworks.splice(i, 1);

                }
            };
        };

        self.drawFireworks = function() {
            var i = self.fireworks.length;
            self.ctx.globalCompositeOperation = 'lighter';
            while (i--) {
                var f = self.fireworks[i];
                self.ctx.lineWidth = f.lineWidth;

                var coordRand = (rand(1, 3) - 1);
                self.ctx.beginPath();
                self.ctx.moveTo(Math.round(f.coordLast[coordRand].x), Math.round(f.coordLast[coordRand].y));
                self.ctx.lineTo(Math.round(f.x), Math.round(f.y));
                self.ctx.closePath();
                self.ctx.strokeStyle = 'hsla(' + f.hue + ', 100%, ' + f.brightness + '%, ' + f.alpha + ')';
                self.ctx.stroke();

                if (self.showTarget) {
                    self.ctx.save();
                    self.ctx.beginPath();
                    self.ctx.arc(Math.round(f.targetX), Math.round(f.targetY), rand(1, 8), 0, Math.PI * 2, false)
                    self.ctx.closePath();
                    self.ctx.lineWidth = 1;
                    self.ctx.stroke();
                    self.ctx.restore();
                }

                if (self.showShockwave) {
                    self.ctx.save();
                    self.ctx.translate(Math.round(f.x), Math.round(f.y));
                    self.ctx.rotate(f.shockwaveAngle);
                    self.ctx.beginPath();
                    self.ctx.arc(0, 0, 1 * (f.speed / 5), 0, Math.PI, true);
                    self.ctx.strokeStyle = 'hsla(' + f.hue + ', 100%, ' + f.brightness + '%, ' + rand(25, 60) / 100 + ')';
                    self.ctx.lineWidth = f.lineWidth;
                    self.ctx.stroke();
                    self.ctx.restore();
                }
            };
        };

        self.bindEvents = function() {
            $(window).on('resize', function() {
                clearTimeout(self.timeout);
                self.timeout = setTimeout(function() {
                    self.canvas.width = self.cw = $(window).innerWidth();
                    self.canvas.height = self.ch = $(window).innerHeight();
                    self.ctx.lineCap = 'round';
                    self.ctx.lineJoin = 'round';
                }, 100);
            });

            //$(self.canvas).on('mousedown', function(e) {
            //    self.mx = e.pageX - self.canvas.offsetLeft;
            //    self.my = e.pageY - self.canvas.offsetTop;
            //    self.currentHue = rand(self.hueMin, self.hueMax);
                ////self.createFireworks(self.cw/2, self.ch, self.mx, self.my); 
            //    self.createParticles(self.mx, self.my, self.currentHue);

            });

        }

        self.clear = function() {
            self.particles = [];
            self.fireworks = [];
            self.ctx.clearRect(0, 0, self.cw, self.ch);
        };


        self.canvasLoop = function() {
            requestAnimFrame(self.canvasLoop, self.canvas);
            self.ctx.globalCompositeOperation = 'destination-out';
            self.ctx.fillStyle = 'rgba(0,0,0,' + self.clearAlpha / 100 + ')';
            self.ctx.fillRect(0, 0, self.cw, self.ch);
            self.updateFireworks();
            self.updateParticles();
            self.drawFireworks();
            self.drawParticles();

        };

        self.init();
        self.fire=function(x,y){
            self.mx = x/1920*self.cw;
            self.my = y/1080*self.ch;
            self.currentHue = rand(self.hueMin, self.hueMax);
            self.createParticles(self.mx, self.my, self.currentHue);
        }

    }
    var fworks = new Fireworks();
    var fw=function(){
      fworks.fire(374,490);
      fworks.fire(404,552);
      fworks.fire(376,580);
      fworks.fire(338,625);
    }
    fw();
    
    setInterval(fw,2000)
    


});*/
